//
//  WKTitleButton.swift
//  WKWeibo
//
//  Created by 恋guang年 on 16/3/29.
//  Copyright © 2016年 恋guang年. All rights reserved.
//

import UIKit

class WKTitleButton: UIButton {
    ///  便利构造函数 title设置可选好处是网络不给力的时候用户名可能加载不出来 也没有缓存 外面不用强制拆包
    convenience init(title:String?,imageName:String){
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        setImage(UIImage(named:imageName), forState: UIControlState.Normal)
        sizeToFit()
        
    }
    ///  重新布局 titleLabel和imageView
    override func layoutSubviews() {
        super.layoutSubviews()
        titleLabel?.frame.origin.x = 0
        imageView?.frame.origin.x = titleLabel!.bounds.width + 3
    }
    
}
